import {request} from "umi";
import {PREFIX} from "@/consts";

export const selectPersons = async () => {
  return request(`${PREFIX}/persons`)
};

export const selectPersonById = async (id: number) => {
  return request(`${PREFIX}/persons/${id}`)
};

export const insertPeron = async (body: API.Person) => {
  return request(`${PREFIX}/persons`,{
    method: "POST",
    data: body
  })
};

export const updatePerson = async (data) => {
  const {values} = data;
  const {id} = data;
  return request(`${PREFIX}/persons/${id}`, {
    method: "PUT",
    data: values
  });
};

export const deletePerson = async (id: number) => {
  return request(`${PREFIX}/persons/${id}`, {
    method: "DELETE",
  })
};
